<!DOCTYPE html>
<html lang="en" class="page-fill" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}" media="all" />
    <style>
        .box {
            width: 100px;
            height: 100px;
            border: 2px solid #858585;
        }

        .img {
            width: 100px;
            height: 100px;
        }

        .pox {
            width: 70px;
            height: 24px;
        }
    </style>
</head>
<body>
    <form >
        名称：<input type="text" class="layui-input">
        备注：<input type="area" class="layui-input">
        <input type="submit" class="layui-btn layui-input">提交
        <input type="reset" class="layui-input layui-btn">重置
    </form>

</body>
<script type="text/javascript"  th:src="@{/lib/layui/layui.js}"></script>
<script th:inline="none">

    layui.use(['form','upload','layer','jquery'], function(){
        form = layui.form;
        var upload = layui.upload;
        form.render('select','test1');
        $ = layui.jquery;
        var edit = $("[name='flag']").val();
        if (edit == "" || edit == null || edit == undefined) {
            $("[name='staffId']").removeAttr("readonly");
        }
        //文件上传渲染

        //身份证正面图片的上传
        var uploadInst = upload.render({
            elem: '#img1' //绑定元素
            ,url: '/api/emp/fileUpload/' //上传接口
            ,done: function(res){
                //上传完毕回调
                $('#imgshow1').attr("src",res.data.src);
                $("input[name ='frontidphoto']").val(res.data.src);

            }
            ,error: function(){
                //请求异常回调
            }
        });

        //身份证反面图片的上传
        var uploadInst = upload.render({
            elem: '#img2' //绑定元素
            ,url: '/api/emp/fileUpload/' //上传接口
            ,done: function(res){
                //上传完毕回调

                $('#imgshow2').attr("src",res.data.src);
                $("input[name ='backidphoto']").val(res.data.src);
            }
            ,error: function(){
                //请求异常回调
            }
        });


        //监听提交
        form.on('submit(empForm)', function(obj) {
            var sysStaffEnclose = obj.field;
            console.log(sysStaffEnclose)
            var method = "";
            var index = top.layer.msg('数据提交中，请稍候', {
                icon : 16,
                time : false,
                shade : 0.8
            });
            if (edit == "" || edit == null || edit == undefined) {
                method = "add";
            } else {
                method = "update";
            }

            $.post("/api/emp/"+method,sysStaffEnclose,function(data){
                if (data.code == 200) {
                    top.layer.close(index);
                    top.layer.msg("员工添加成功！");
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                } else {
                    layer.msg(data.msg,{"icon":2});
                }

            })

            return false;
        });

    });
</script>


</html>